package Group9.TodoManager.DataStore;

import Group9.TodoManager.DataStore.Interface.ISearchQuery;

/**
 * Generic Abstract Repository class.
 * This class is made generic so that it supports any kind of class T which is
 * determined in runtime. This helps to reuse this abstract class Repository in
 * many other applications as well. This class is made abstract class because we
 * can have different kinds of data storage like memory data store / xml data
 * store / database etc. So, this class abstracts those all classes of
 * repositories.
 * @author Rupesh
 */
public abstract class Repository<T>
{
    /**
     * THERE SHOULD BE A MECHANISM FOR ADDING NEW ITEMS INTO THE REPOSITORY.
     * THIS METHOD IS RESPONSIBLE FOR ADDING NEW ITEMS INTO DATA STORE
     * @param item
     */
    public abstract void addNewItem(T item);

    /**
     * THERE SHOULD BE A MECHANISM FOR UPDATING/EDITING AN ITEM
     * THIS METHOD IS RESPONSIBLE FOR UPDATING/EDITING AN ITEM
     * @param oldItem THE OLD ITEM THAT IS TO BE UPDATED
     * @param newItem THE NEW ITEM BY WHICH THE OLD ITEM IS TO BE REPLACED WITH
     */
    public abstract void updateItem(T oldItem, T newItem);

    /**
     * Update property of the item
     * @param item old item that is to be updated
     * @param propertyName name of the property to be updated
     * @param value new value of the property
     * @return updated item
     */
    public abstract T updateItemProperty(T item, String propertyName, Object value);
    
    /**
     * THERE SHOULD BE SOME MECHANISM FOR SELECTING ITEMS FROM THE DATA STORE
     * THERE CAN BE DIFFERENT CRITERIA(E.G. DATE/PRIORITY etc) FOR RETRIEVING
     * ITEMS FROM THE DATA STORE SO WE NEED A ITEMFETCHER TO FETCH A ITEM FROM
     * THE DATA STORE
     * @param query
     * @return
     */
    public abstract Iterable<T> getItem(ISearchQuery query);

    /**
     * THERE SHOULD BE SOME MECHANISM FOR REMOVING AN ITEM FROM THE DATASTORE
     * THIS METHOD IS RESPONSIBLE FOR REMOVING THE ITEMS FROM THE DATASTORE
     * THE METHOD TO REMOVE AN ARRAY OF ITEMS CAN BE
     * DECLARED IN THE CONCRETE CLASS BY MAKING CALLS TO THIS METHOD
     * @param item
     */
    public abstract void removeItem(T item);

    /**
     * FINALIZING FUNCTION. IN XML DATASTORE IT DUMPS THE MEMORY DOM IN THE FILE
     */
    public void Commit(){}
}